home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 05 - 1989 / 05.04 Apr 89 / DA Icon / DA Icon Code Segments next >
Encoding:
Text File  |  1989-03-15  |  4.6 KB  |  207 lines  |  [TEXT/nX^n]

  1.  
  2. setMenuIcon    MACRO    &1,&2,&3    ; MenuHandle,Menu Item #,ICON Name.
  3.  
  4.         ; First, retrieve the attached ICON Resource:
  5.         
  6.         move.w    RescIDBase,iconID
  7.         addi.w    #&2,iconID
  8.         GetIcon    iconID,=iconHdl
  9.         move.l    iconHdl,tempHdl            ; Just temporary, folks !!
  10.     
  11.         ; Then, get the Resource file's Attributes so we can
  12.         ; reset them later.  After that, we make a copy of the
  13.         ; ICON's Handle so that we can use the COPY for the MENU:
  14.         
  15.         HomeResFile    iconHdl,=resFileRef
  16.         GetResFileAttrs    resFileRef,=resFileAttrs
  17.         ; ----------
  18.         move.l    iconHdl,a0
  19.         _HandToHand
  20.         move.l    a0,cyHdl
  21.         ReleaseResource    tempHdl        ; The ORIGINAL Resource.
  22.         
  23.         ; Now, place the ICON's COPY in the Menu Item by
  24.         ; changing the ICON's ID # to between 257 --> 511:
  25.         
  26.         move.w    #&2,iconID
  27.         addi.w    #256,iconID
  28.         AddResource    cyHdl,#'ICON',iconID,!.name
  29.         bra.s    .1
  30. .name        text    #&&3
  31.         align
  32.  
  33.         ; Reset to ORIGINAL Attributes to clear the resChanged
  34.         ; Bit in the Attribute Byte so that we don’t update the
  35.         ; Resource upon Closing AND so "Suitcase" DOES reset to
  36.         ; the disk-based ID:
  37.  
  38. .1        SetResFileAttrs    resFileRef,resFileAttrs
  39.         SetItmIcon    &1,#&2,#&2            ; menuHandle,item #,icon #.
  40.         
  41.         ENDM
  42.  
  43.  
  44.  
  45.         move.l    #6,d0                ; "jmp  myMenuDefProc".
  46.         _NewHandle,clear
  47.         move.l    a0,myMenuDefHdl
  48.         bra.s    .skipCode
  49.         ; ----------
  50. .code        jmp    $CCCCCCCC            ; 6 bytes.
  51. .absAddr    dc.l    myMenuDefProc-.absAddr
  52.         ; ----------
  53. .skipCode    move.l    (a0),a0            ; Convert to a Pointer.
  54.         lea    .code,a1
  55.         move.w    (a1)+,(a0)+        ; Object Code word for "jmp".
  56.         lea    .absAddr,a1
  57.         move.l    (a1),d1
  58.         lea    (a1,d1.l),a1            ; Absolute address of
  59.         move.l    a1,(a0)            ;   "myMenuDefProc".
  60.  
  61.         …
  62.         …
  63.  
  64.         NewMenu    dCtlMenu,!newMenuName,=mainMenuHdl
  65.         AppendMenu    mainMenuHdl,!mainMenuItems
  66.         InstallMenuProc    mainMenuHdl
  67.  
  68.         …
  69.         …
  70.  
  71.  
  72. InstallMenuProc    MACRO    &1            ; MenuHandle.
  73.  
  74.         move.l    &1,a1                    ; Handle -->
  75.         move.l    (a1),a1                ;   Pointer.
  76.         move.l    myMenuDefHdl,menuDefHandle(a1)    ; _NewHandle into Menu Record.
  77.         ; ----------
  78.         CalcMenuSize    &1
  79.         
  80.         ENDM
  81.  
  82.  
  83.  
  84. ; ======================================
  85. ; FUNCTION  doChooseMessage (myMenu:MenuHandle; myRect:Rect; myPoint:Point;
  86. ;                    oldItem:INTEGER) : INTEGER;
  87. ;
  88. ; Returns Menu Item # you selected:
  89.  
  90. doChooseMessage    func    integer
  91. .myMenu        handle
  92. .myRect        pointer
  93. .myPoint        point
  94. .oldItem        integer
  95.             endParms
  96.         
  97.             locals
  98. .oldRect        rect
  99. .itemKey        char
  100. .itemMark        char
  101. .itemRect        rect
  102.             endLocals
  103.         
  104. .menuHdl        requ    a1            ; My worker bees ...
  105. .cyParamBlkPtr    requ    a2
  106. .cyDCEPtr        requ    a3
  107. .menuReg        requ    a4
  108. .theItem        requ    d3            ; Counts Items to get current one.
  109. .enableFlags        requ    d4            ; A disabled
  110. .shift            requ    d0            ;   item ??
  111.  
  112.         
  113.         enter
  114.         
  115.         movem.l    d1-d7/a0-a4,-(sp)    ; All your goodies.
  116.         ; ==========
  117.  
  118.         move.l    .myMenu,.menuHdl        ; Handle -->
  119.         move.l    (.menuHdl),.menuReg        ;   Pointer.
  120.         ;
  121.         PtInRect    .myPoint,.myRect,=d0
  122.         beq    .outsideMRect
  123.  
  124.         moveq    #0,.theItem            ; Initialize counter.
  125.         
  126. .chooseLoop    addq.w    #1,.theItem
  127.         push.l    .myMenu
  128.         push.l    .myRect
  129.         push.w    .theItem
  130.         pea    .itemRect
  131.         bsr    GetItemRect
  132.         ; ----------                
  133.         PtInRect    .myPoint,!.itemRect,=d1
  134.         beq.s    .chooseLoop
  135.         
  136.         move.l    menuID(.menuReg),d2        ; Support _MenuChoice
  137.         move.w    .theItem,d2        ;   for the Mac II.
  138.         move.l    d2,MenuDisable
  139.         
  140. .disabled?    move.l    menuEnable(.menuReg),.enableFlags
  141.         BitAnd    .enableFlags,#1,=d0        ; Bit #0 for ENTIRE Menu.
  142.         beq.s    .yup                ; ... it's disabled.
  143.         ; ----------
  144.         moveq    #1,.shift
  145.         lsl.l    .theItem,.shift        
  146.         BitAnd    .enableFlags,.shift,=d1
  147.         bne.s    .deSelectOld
  148.         ; ----------                
  149. .yup        moveq    #0,.theItem            ; Item is disabled.
  150.  
  151. .deSelectOld    cmp.w    .oldItem,.theItem
  152.         beq    .aSelection
  153.         tst.w    .oldItem
  154.         beq.s    .selectNew            ; The MenuBar, so don't invert back.
  155.         ; ----------                
  156.         push.l    .myMenu
  157.         push.l    .myRect
  158.         push.w    .oldItem
  159.         pea    .oldRect
  160.         bsr    GetItemRect
  161.         InverRect    !.oldRect        ; Invert back to white, or de-select.
  162.  
  163. .selectNew    tst.w    .theItem
  164.         beq.s    .itsDisabled
  165.         ; ----------                
  166.         InverRect    !.itemRect        ; Blacken current selection.
  167.  
  168.         push.l    .myMenu
  169.         push.w    .theItem
  170.         pea    .itemKey
  171.         bsr    GetItemKey
  172.         cmpi.w    #hMenuCmd,.itemKey
  173.         bne.s    .aSelection
  174.         ;
  175.         GetItmMark    .myMenu,.theItem,!.itemMark
  176.         GetMHandle    .itemMark,=a0        ; = MenuHandle.
  177.         clr.l    -(sp)
  178.         push.l    a0
  179.         push.l    .myPoint
  180.         bsr    PopupSelect
  181.         pop.l    d1
  182.         tst.w    d1
  183.         beq.s    .onMenuBar            ; Item's disabled.
  184.         move.w    #31,.theItem        ; ... fake out Menu Manager so it
  185.                             ;     doesn't blink a parent item.
  186. .itsDisabled
  187. .aSelection    move.w    .theItem,.result
  188.         bra.s    .end
  189.         ; ==========
  190.         
  191. .outsideMRect    tst.w    .oldItem
  192.         beq.s    .onMenuBar
  193.         ; ----------                
  194.         push.l    .myMenu
  195.         push.l    .myRect
  196.         push.w    .oldItem
  197.         pea    .oldRect
  198.         bsr    GetItemRect
  199.         InverRect    !.oldRect        ; Back to white.
  200.         
  201. .onMenuBar    clr.w    .result
  202.  
  203.         ; ==========
  204. .end        movem.l    (sp)+,d1-d7/a0-a4    ; Withdraw your life savings !!
  205.         
  206.         exit
  207.